package org.llc.authorization.config.extend;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.llc.common.starter.model.UserAccount;

/**
 * 集成认证-认证器抽象类
 *
 * @author llc
 * @date 2020/2/27 10:58
 * @since 1.0.0
 */
@Slf4j
public abstract class AbstractPrepareIntegrationAuthenticator implements IntegrationAuthenticator{

    /**
     * 预处理打印认证方式
     * {@inheritDoc}
     * @author llc
     * @date 2020/2/28 12:24
     */
    @Override
    public void prepare(IntegrationAuthenticationEntity entity) {
        log.info("IntegrationAuthenticator prepare this is authType -> {}",authTypeHandle(entity.getAuthType()));
    }

    /**
     * 认证结束后执行
     * {@inheritDoc}
     * @author llc
     * @date 2020/2/28 16:46
     */
    @Override
    public void complete(IntegrationAuthenticationEntity entity) {
        log.info("IntegrationAuthenticator complete this is authType -> {}",authTypeHandle(entity.getAuthType()));
    }

    /**
     * 集成认证中除用户名密码不进行密码查询与校验
     * @param userAccount 用户账户对象
     * @author llc
     * @date 2020/2/27 17:27
     */
    void setEmptyPassword(UserAccount userAccount){
        userAccount.setPassword("");
    }

    /**
     * 认证类型处理
     * <p>返回实际的认证类型</p>
     * @param authType  认证类型
     * @return java.lang.String
     * @author llc
     * @date 2020/2/28 16:53
     */
    private String authTypeHandle(String authType){
        return StringUtils.isEmpty(authType) ? "password" : authType;
    }
}
